package com.concorrency.learn.service;

import com.concorrency.learn.model.Money;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * Created by corey on 2018/9/8.
 */
@Service
public class MoneyService {
     public Money getMoney(int id){
         Money money;
         if (id == 1) {
             money = new Money(new BigDecimal(10000000));
         }else{
             money = new Money(new BigDecimal(0));
         }
         try {
             long time = (long) (Math.random() * 10000);
             Thread.sleep(time);
             System.out.println(Thread.currentThread().getName()+"，getMoney沉睡了"+time+"毫秒");
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
         return money;


     }
}
